home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / serial_lib / serial_lib.h < prev   
Encoding:
Text File  |  1994-05-04  |  3.4 KB  |  105 lines  |  [TEXT/KAHL]

  1. /* serial_lib.h */
  2.  
  3. // 5/2/94 by Darrell Anderson and Andy Forsberg
  4.  
  5. #ifndef __SERIAL_LIB__
  6. #define __SERIAL_LIB__
  7.  
  8. // easy enums to reference the serial ports.  Use one of these as the parameter describing which
  9. // port to use for each function in this lib.
  10. //
  11. // to expand (to account for more serial ports), just insert new entries such that all values
  12. // 0..(the total number of ports) have been defined and that k_NumSerialPorts is the last entry.
  13. // FOLLOW THIS GUIDE!  you'll also have to edit the device name array entries below
  14. enum {
  15.     modemPort = 0,
  16.     printerPort = 1,
  17.     quadraLink1 = 2,
  18.     quadraLink2 = 3,
  19.     quadraLink3 = 4,
  20.     quadraLink4 = 5,
  21.     k_NumSerialPorts = 6
  22. };
  23.  
  24. // baud rates (this is a collection of magic numbers). binary OR them together to specify
  25. // desired port features.  typical settings are illustrated below (feel free to use them or
  26. // define your own in a similar manner). 
  27. #ifndef __SERIAL__
  28. enum {
  29.     baud9600 = 10,
  30.     baud19200 = 4,
  31.     baud57600 = 0,
  32.     stop10 = 16384,
  33.     stop15 = -32768,
  34.     stop20 = -16384,
  35.     noParity = 0,
  36.     oddParity = 4096,
  37.     evenParity = 12288,
  38.     data7 = 1024,
  39.     data8 = 3072
  40. };
  41. #endif
  42.  
  43. // some sample serial port settings..
  44. // binary OR together the features we want
  45. #define standard_9600    ( baud9600 | data8 | stop10 | noParity )            
  46. #define standard_19200     ( baud19200 | data8 | stop10 | noParity )
  47. #define standard_57600    ( baud57600 | data8 | stop10 | noParity )
  48.  
  49. // how many seconds until we timeout (trying to read from a serial port)
  50. #define k_serialTimeout 2
  51.  
  52. //===================================================================
  53. // you probably won't use anything in this segment (between these '=' lines).
  54.  
  55. // these are _only_ referenced in serial_lib.c, so only that code knows about them.
  56. #ifdef __IN_SERIAL_LIB__
  57.  
  58. // these are used internally -- don't worry about them.. change only to account
  59. // for other ports (adding new ports, using different port names, etc)
  60.  
  61. // note: to add new ports, first change the enum at top (as per the instructions up there)
  62. // then add the corresponding driver names ("in","out") driver names to the list below.
  63.  
  64. #define k_NoDeviceDriverNameMayHaveMoreThanThisManyCharacters 30
  65.  
  66. char k_DeviceDriverNames[(2*k_NumSerialPorts)][k_NoDeviceDriverNameMayHaveMoreThanThisManyCharacters] = 
  67. {
  68.     // printer port: (in,out)
  69.         "\p.AIn","\p.AOut",
  70.     // modem port: (in,out)
  71.         "\p.BIn","\p.BOut",
  72.     // quadralink ports (1 is right-most when looking at the back)
  73.         "\p.QuadraLink Port 1InD","\p.QuadraLink Port 1OutD",
  74.         "\p.QuadraLink Port 2InD","\p.QuadraLink Port 2OutD",
  75.         "\p.QuadraLink Port 3InD","\p.QuadraLink Port 3OutD",
  76.         "\p.QuadraLink Port 4InD","\p.QuadraLink Port 4OutD"
  77. };
  78.  
  79. // these are used in error handling functions to describe which port went screwy to the user.
  80. // proper names aren't as important here, but are nice.  they should have the same ordering as
  81. // in the original enum.
  82. char k_UnderstandablePortNames[k_NumSerialPorts][k_NoDeviceDriverNameMayHaveMoreThanThisManyCharacters] =
  83. {
  84.     "modemPort",
  85.     "printerPort",
  86.     "quadraLink1",
  87.     "quadraLink2",
  88.     "quadraLink3",
  89.     "quadraLink4"
  90. };
  91.  
  92. #endif
  93.  
  94. //===================================================================
  95. // function prototypes:
  96.  
  97. void InitSerial( int whichSerialPort, short configurationParameter );
  98.  
  99. void CloseSerial( int whichSerialPort );
  100.  
  101. void ReadFromSerial( int whichSerialPort, long howManyBytes, Ptr dataPtr );
  102.  
  103. void WriteToSerial( int whichSerialPort, long howManyBytes, Ptr dataPtr );
  104.  
  105. #endif